﻿using System;
using System.Collections.Generic;
using System.Threading;

namespace wspol_zad3
{
    public class ThreadMenager
    {
        private Buffors buffors;
        private bool exit;
        private Random rand;

        public ThreadMenager(Buffors b)
        {
            buffors = b;
            exit = false;
            rand = new Random();
        }

        public void Producer(object ms)
        {
            while(!exit)
            {
                //
                Thread.Sleep((int)ms);
                buffors.b1Put(rand.Next(1,100));
            }
        }

        public void FromB1ToB2(object ms)
        {
            int elem;

            while (!exit)
            {
                elem = buffors.b1Get();
                Thread.Sleep((int)ms);
                buffors.b2Put(elem);
            }
        }

        public void ClearB2()
        {
            while (!exit)
            {
                buffors.b2Clear();
            }
        }

        public void ShutDown()
        {
            exit = true;
        }
    }
}
